package com.xsir.ditan.miniprogram.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author user
 * @date 2021/1/28
 */
public class JsonUtil {
    private static ObjectMapper objectMapper = new ObjectMapper();
    
    public static Object toObject(String json, Class<?> classType) {
        Object obj = null;
        
        try {
            obj = objectMapper.readValue(json, classType);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        
        return obj;
    }
    
    public static String toJson(Object obj) {
        String json = null;
        
        try {
            json = objectMapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        
        return json;
    }
    
}
